<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login" @keydown.enter="handleSubmit">
    <div class="login-con">
      <Card :bordered="false">
        <p slot="title">
          <Icon type="log-in"></Icon>
          欢迎登录
        </p>
        <div class="form-con">
          <Form ref="loginForm" :model="form" :rules="rules">
            <FormItem prop="loginName">
              <Input v-model="form.loginName" placeholder="请输入用户名">
              <span slot="prepend">
                                    <Icon :size="16" type="person"></Icon>
                                </span>
              </Input>
            </FormItem>
            <FormItem prop="passWord">
              <Input type="password" v-model="form.passWord" placeholder="请输入密码">
              <span slot="prepend">
                                    <Icon :size="14" type="locked"></Icon>
                                </span>
              </Input>
            </FormItem>
            <FormItem>
              <Button @click="handleSubmit" type="primary" long>登录</Button>
            </FormItem>
          </Form>
          <p class="login-tip">输入用户名和密码</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import util from '@/lib/util.js';

  export default {
    data() {
      return {
        form: {
          loginName: 'Angel',
          passWord: '123'
        },
        rules: {
          loginName: [
            {required: true, message: '账号不能为空', trigger: 'blur'}
          ],
          passWord: [
            {required: true, message: '密码不能为空', trigger: 'blur'}
          ]
        }
      };
    },
    methods: {
      handleSubmit() {
        let that = this;
        this.$refs.loginForm.validate((valid) => {
          if (valid) {

            util.post('/auth/jwt/token',this.form,function(res){
              Cookies.set('angel-bo-token', res);
              that.$router.push({
                name: 'admin'
              });
            });

          }
        });
      }
    }
  };
</script>

<style>

</style>
